class index {
    constructor() {
        this.$('#waper').addEventListener('click', this.sjwt)
        // console.log(this.$('#waper'));
        this.paoMaled()
        this.ysdl()
    }
    // 右上角登录的点击事件
    ysdl = () => {
        let dl = this.$('#ysdl')
        // let zc = this.$('#zhuce')
        let name = localStorage.getItem('nickname')
        let id = localStorage.getItem('user_id')
        // console.log(name);
        // console.log(zc);
        if (name) {
            dl.innerHTML = name
            // zc.innerHTML = `<img src="../../html/课上代码/icon1.jpg" alt="" width='20px' height='20px'>`
        }
        // 登录过期的处理
        if (name == '' || id == '') {

            // 登录超时就清除保存的值
            localStorage.removeItem('token')
            localStorage.removeItem('user_id')

            // 跳转到购物车当登录后跳转到本页面
            location.assign('./login.html?ReturnUrl=./shopcar2.html')
        }


    }
    sjwt = (eve) => {
        // console.log(111);
        // console.log(this);
        // console.log(eve.target);
        let tar = eve.target
        // console.log(tar.nodeName);
        if (tar.id == 'items1') {
            location.assign('./product.html')
        }
    }
    //跑马灯
    paoMaled() {
        var marqueeBox = document.getElementById("marquee-box");
        var marquee = document.getElementById("marquee");
        var marqueeCopy = document.getElementById("marquee-1");

        // console.log(marqueeBox,marquee,marqueeCopy);
        marqueeCopy.innerHTML = marquee.innerHTML;
        function fun() {
            //从右向左
            if (marqueeBox.scrollLeft >= 800) {
                marqueeBox.scrollLeft = 0;
            } else {
                marqueeBox.scrollLeft++;
            }
        }

        let fun1 = setInterval(fun, 18);

        marqueeBox.onmouseover = function () {
            //鼠标经过时  清除定时器  停止图片的滚动
            clearInterval(fun1);
        };
        marqueeBox.onmouseout = function () {
            //鼠标离开后  继续滚动图片
            fun1 = setInterval(fun, 50);
        };

    }






















    // 封装一个获取节点的方法
    $(ele) {
        let res = document.querySelectorAll(ele)
        return res.length == 1 ? res[0] : res;
    }
}







new index;